package com.tlw.practice.tlw.service.impl;

import com.tlw.practice.tlw.common.ResultCode;
import com.tlw.practice.tlw.dao.AuditDao;
import com.tlw.practice.tlw.entity.AuditEntity;
import com.tlw.practice.tlw.entity.LeaveEntity;
import com.tlw.practice.tlw.service.AuditService;
import com.tlw.practice.tlw.utils.BeanChangeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class AuditServiceImpl implements AuditService {

    @Autowired
    private AuditDao auditDao;

    @Override
    public ResultCode recodeChange(Object oldLeave, Object newLeave) {
        BeanChangeUtil<LeaveEntity> t = new BeanChangeUtil<>();
        String str = t.contrastObj(oldLeave, newLeave);
        if (str.equals("")) {
            System.out.println("未有改变");
        } else {
            System.out.println(str);
        }
        return null;
    }

    @Override
    public List<AuditEntity> findOneByLeaveId(String leaveId) {
        return auditDao.findByObjectId(leaveId);
    }

    @Override
    @Transactional
    public int saveAudit(AuditEntity audit) {
        AuditEntity save = auditDao.save(audit);

        if (save != null){
            return 1;
        }
        return 0;
    }
}
